package com.lc.ibps.platform.rest.org;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lc.ibps.api.org.service.IPartyRoleMgrService;
import com.lc.ibps.base.core.util.AppUtil;
import com.lc.ibps.cloud.entity.APIResult;
import com.lc.ibps.web.controller.BaseApiController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/** 角色控制器，第三方系统调用
 *
 * <pre> 
 * 构建组：ibps-platform-webapi
 * 作者：Lium
 * 邮箱：1316679699@qq.com
 * 日期：2017年7月19日-上午11:36:19
 * 版权：广州流辰信息技术有限公司版权所有
 * </pre>
 */

@RequestMapping(value="/api/webapi/roleMgrService")
@Api(value = "/roleMgrService",tags="用户管理-角色管理服务")
@RestController
public class RoleMgrController extends BaseApiController{
	
	private IPartyRoleMgrService roleMgrService;
	
	public RoleMgrController(){
		roleMgrService = AppUtil.getBean(IPartyRoleMgrService.class);
	}
	
	/**
	 * 添加角色信息
	 *
	 * @param json {id:""/*选填/,name:"测试"/*必填/,roleAlias:"cs"/*必填/,roleNote:"角色描述"/*选填/,subSystemId:""/*选填/}
	 */
	@ApiOperation(value = "添加角色信息", notes = "添加角色信息")
	@RequestMapping(value="/createRole",method=RequestMethod.PUT)
	public APIResult<String> createRole(
			@ApiParam(value = "角色信息json", required = true) @RequestParam(name = "json", required = true) String json){	
		APIResult<String> result = new APIResult<>();
		try{
			roleMgrService.createRole(json);
		}catch(Exception e){
			result = getExceptionResult(result, ERROR, "添加角色信息失败！", e);
		}
		return result;
	}
	
	/**
	 * 修改角色信息
	 *
	 * @param json {id:"3b463b30",name:"测试"/*必填/,roleAlias:"cs"/*必填/,roleNote:"角色描述"/*选填/,subSystemId:"1"/*选填/}
	 */
	@ApiOperation(value = "修改角色信息", notes = "修改角色信息")
	@RequestMapping(value="/updateRole",method=RequestMethod.POST)
	public APIResult<String> updateRole(
			@ApiParam(value = "角色信息json", required = true) @RequestParam(name = "json", required = true) String json){		
		APIResult<String> result = new APIResult<>();
		try{
			roleMgrService.updateRole(json);
		}catch(Exception e){
			result = getExceptionResult(result, ERROR, "修改角色信息失败！", e);
		}
		return result;
	}
	
	@ApiOperation(value = "删除角色信息", notes = "根据id删除角色")
	@RequestMapping(value="/deleteRole",method=RequestMethod.DELETE)
	public APIResult<String> deleteRole(
			@ApiParam(value="角色ID", required = true)
			@RequestParam(name = "id", required = true) String id
			){
		APIResult<String> result = new APIResult<>();
		try{
			roleMgrService.deleteRole(id);
		}catch(Exception e){
			result = getExceptionResult(result, ERROR, "删除角色信息失败！", e);
		}
		return result;
	}
}
